#include <cstring>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <cstdlib>

#define MAXN 20001
#define MAX 1001
#define INF 999999999

using namespace std;

int n, p, k;

struct Edge
{
  int v, w, next;
  int flag;
} edge[MAXN];

int head[MAX];
int weight[MAXN];
int dis[MAXN];
bool vis[MAXN];
int e;

void add(int u, int v, int w)
{
  edge[e].v = v;
  edge[e].w = w;
  edge[e].next = head[u];
  head[u] = e++;
}

void init()
{
  e = 0;
  memset(head, -1, sizeof(head));
}

int dijkstra(int s, int e)
{
  for (int i = 1; i <= n; i++)
  {
    dis[i] = INF;
    vis[i] = false;
  }

  for (int i = head[1]; i != -1; i = edge[i].next)
  {
    int v = edge[i].v;
    dis[v] = edge[i].flag;
  }

  dis[s] = 0;
  vis[s] = true;

  for (int i = 2; i <= n; i++)
  {
    int mi = INF;
    int u = 1;

    for (int j = 1; j <= n; j++)
    {
      if (!vis[j] && dis[j] < mi)
      {
        mi = dis[j];
        u = j;
      }
    }

    vis[u] = true;

    for (int j = head[u]; j != -1; j = edge[j].next)
    {
      int v = edge[j].v;

      if (!vis[v] && dis[u] + edge[j].flag < dis[v])
      {
        dis[v] = dis[u] + edge[j].flag;
      }
    }
  }

  return dis[n];
}

void solve()
{
  weight[p + 1] = 0;

  sort(weight, weight + p + 1);

  int low = 0, high = p;
  int mid = high;
  int flag = false;

  while (low <= high)
  {
    for (int i = 1; i <= n; i++)
    {
      for (int j = head[i]; j != -1; j = edge[j].next)
      {
        if (edge[j].w > weight[mid])
        {
          edge[j].flag = 1;
        }
        else
        {
          edge[j].flag = 0;
        }
      }
    }

    int dist = dijkstra(1, n);

    if (dist <= k)
    {
      high = mid - 1;
    }
    else
    {
      low = mid + 1;
    }

    if (dist != INF)
    {
      flag = true;
    }
    mid = (low + high) >> 1;
  }

  if (!flag)
  {
    printf("-1\n");
  }
  else
  {
    printf("%d\n", weight[low]);
  }
}

void input()
{
  int a, b, l;

  init();

  scanf("%d %d %d", &n, &p, &k);

  for (int i = 0; i < p; i++)
  {
    scanf("%d %d %d", &a, &b, &l);
    weight[i] = l;
    add(a, b, l);
    add(b, a, l);
  }

  solve();
}

int main()
{
  input();
  return 0;
}
